#include <stdio.h>
#define MAXLINE 1000
#define YES 1
#define NO 0

void myGetline(char line[], int maxline);
int any(char s1[], char s2[]);

int main(void) {
    char s1[MAXLINE], s2[MAXLINE];
    int val;
    myGetline(s1, MAXLINE);
    myGetline(s2, MAXLINE);
    val = any(s1, s2);
    printf("%d\n%s%s", val, s1, s2);
    return 0;
}

void myGetline(char line[], int maxline) {
    int i, c;
    for (i = 0; i < maxline && (c = getchar()) != EOF && c != '\n'; ++i) {
        line[i] = c;
    }
    if (c == '\n') {
        line[i++] = c;
    }
    line[i] = '\0';
}

int any(char s1[], char s2[]) {
    int i, j, checkNext;
    checkNext = YES;
    for (i = 0; (s1[i] != '\0') && (checkNext == YES); ++i) {
        for (j = 0; (s2[j] != '\0'); ++j) {
            if (s1[i] == s2[j]) {
                checkNext = NO;
                break;
            }
        }
    }
    if (s1[i] == '\0') {
        return -1;
    } else {
        return i;
    }
}